package com.stn.zjx.givingtreasure.adapter;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.google.android.flexbox.FlexboxLayout;

import com.jaeger.ninegridimageview.ItemImageClickListener;
import com.jaeger.ninegridimageview.ItemImageLongClickListener;
import com.jaeger.ninegridimageview.NineGridImageView;
import com.jaeger.ninegridimageview.NineGridImageViewAdapter;
import com.luck.picture.lib.tools.DateUtils;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.orhanobut.logger.Logger;
import com.stn.zjx.givingtreasure.MainActivity;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.activity.UserLoginActivity;
import com.stn.zjx.givingtreasure.activity.common.DropImgsShowActivity;
import com.stn.zjx.givingtreasure.activity.dynamic.DynamicDetailActivity;
import com.stn.zjx.givingtreasure.activity.dynamic.DynamicVideoDetailActivity;
import com.stn.zjx.givingtreasure.activity.web.GenericWebActivity;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.bean.DynamicDetail;
import com.stn.zjx.givingtreasure.domain.DynamicShowDomain;
import com.stn.zjx.givingtreasure.fragment.active.DynamicFragment;
import com.stn.zjx.givingtreasure.net.WebApi;
import com.stn.zjx.givingtreasure.net.impl.UserDynamicLikeNetImpl;
import com.stn.zjx.givingtreasure.service.UserService;
import com.stn.zjx.givingtreasure.table.User;
import com.stn.zjx.givingtreasure.utils.AMapUtils;
import com.stn.zjx.givingtreasure.utils.LngLat;
import com.stn.zjx.givingtreasure.utils.OpenLocalMapUtil;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;
import com.vondear.rxtools.RxActivityTool;
import com.zzhoujay.richtext.RichText;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Consumer;
import me.shaohui.bottomdialog.BottomDialog;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.widget.media.IjkVideoView;

import static com.mob.tools.utils.Strings.getString;
@SuppressWarnings("all")
public class DynamicShowItemListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

   public List<DynamicDetail> dataBeanList=new ArrayList<>();
   private LayoutInflater inflater;

   public DynamicFragment fragment;
   public BaseActivity context;
   public DynamicShowItemListAdapter(BaseActivity activity, DynamicFragment fragment) {
       inflater = LayoutInflater.from(activity);
       this.context=activity;
       this.fragment=fragment;
   }

   @Override
   public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       RecyclerView.ViewHolder vh = new IndexHolder(inflater.inflate(R.layout.item_dynamic_active_show, parent, false));
       return vh;
   }
   @SuppressLint({"SetTextI18n", "ClickableViewAccessibility", "CheckResult"})
   @Override
   public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
                   IndexHolder ih= (IndexHolder) viewHolder;
       DynamicDetail     dataBean=dataBeanList.get(i);

       Glide
               .with(context)
                 .asBitmap()
               .thumbnail(0.2f)
               .apply(new RequestOptions().placeholder(R.mipmap.default_avatar).error(R.mipmap.default_avatar))
               .load(dataBean.getUserAvatar())
               .into(new SimpleTarget<Bitmap>() {
                   @Override
                   public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        ih.cir.setImageBitmap(resource);
                   }

                   @Override
                   public void onLoadFailed(@Nullable Drawable errorDrawable) {
                       super.onLoadFailed(errorDrawable);
                       ih.cir.setImageResource(R.mipmap.default_avatar);
                   }
               });

           ih.user_nickname.setText(dataBean.getUserNickname());
           ih.address.setText(dataBean.getDynamicAddress());
           if(dataBean.getLocationLongitude()!=0&&dataBean.getLocationLatitude()!=0
                   &&fragment.longitude!=0&&fragment.latitude!=0){
               ih.nav_location.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View view) {
                       openMapDialog(fragment.fromAddress+"",dataBean.getDynamicAddress(),String.valueOf(fragment.longitude),
                               String.valueOf(fragment.latitude),
                               String.valueOf(dataBean.getLocationLongitude()),
                               String.valueOf(dataBean.getLocationLatitude())
                       );
                   }
               });
           }else{
               ih.nav_location.setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View view) {
                   }
               });
           }
           ih.time.setText(ToolsUtils.getDateBeforeAfter(dataBean.getDynamicCreatedate()));



            if(fragment.latitude==0||fragment.longitude==0){
              ih.km.setText(context.getString(R.string.unable_get_distance));
            }else{
               double m=AMapUtils.calculateLineDistance(new LngLat(fragment.longitude,fragment.latitude),
                        new LngLat(dataBean.getLocationLongitude(),
                                dataBean.getLocationLatitude()));
                ih.km.setText(ToolsUtils.getM(m));
            }
            ih.content.setText(dataBean.getDynamicContent());
            if(ih.content.getLineCount()>=5){
           ih.expand.setVisibility(View.VISIBLE);
           }else{
               ih.expand.setVisibility(View.GONE);
           }


       ih.expand.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               Bundle bundle=new Bundle();
               bundle.putInt("id",dataBean.getUserDynamicId());
               RxActivityTool.skipActivity(context, DynamicDetailActivity.class,bundle);
           }
       });
       String[] orign_imgs=dataBean.getDynamicImgs().split("\\*");
            List<String> new_imgs=new ArrayList<>();
            for(int o=0;o<orign_imgs.length;o++){
                if(!TextUtils.isEmpty(orign_imgs[o])){
                    new_imgs.add(orign_imgs[o]);
                }
             }

       ih.videoView.release(true);
       ih.videoView.stopPlayback();
       ih.tv_duration.setVisibility(View.GONE);
       ih.tv_duration.setVisibility(View.GONE);
       ih.tv_duration.setText("00.00");
       ih.tv_duration_right.setText("00.00");

       ih.isPlay=false;
       ih.play_video.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {

           }
       });
       ih.video_layout.setVisibility(View.GONE);
       ih.single_iv.setImageDrawable(null);
       ih.single_iv.setVisibility(View.GONE);
       ih.single_iv.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View view, MotionEvent motionEvent) {
               return false;
           }
       });
//       ih.nineGrid.setImagesData(new ArrayList<>(),NineGridImageView.STYLE_GRID);
       ih.nineGrid.setVisibility(View.GONE);
        switch (dataBean.getDynamicContentType()){
            case 0:
                if(new_imgs.size()==1){
                       ih.single_iv.setVisibility(View.VISIBLE);
                    ih.single_iv.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                       Glide.with(context)
                               .load(new_imgs.get(0))
                               .thumbnail(0.2f)
                               .into(new SimpleTarget<Drawable>() {
                                   @Override
                                   public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {

                                       ih.single_iv.setImageDrawable(resource);

                                       ih.single_iv.setOnTouchListener((view, event) -> {

                                           switch (event.getAction()) {
                                               case MotionEvent.ACTION_DOWN:
                                                    ih.origin_x=event.getX();
                                                    ih.origin_y=event.getY();
                                                   Drawable drawable =ih.single_iv.getDrawable();
                                                   if (drawable != null) {
                                                       drawable.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
                                                   }
                                                   break;
                                               case MotionEvent.ACTION_MOVE:
                                                   break;
                                               case MotionEvent.ACTION_CANCEL:
                                               case MotionEvent.ACTION_UP:
                                                   Drawable drawableUp =ih.single_iv .getDrawable();
                                                   if (drawableUp != null) {
                                                       drawableUp.mutate().clearColorFilter();
                                                   }
                                                   if(ih.origin_x==event.getX()&&
                                                           ih.origin_y==event.getY()){
                                                       Intent intent=new Intent(context, DropImgsShowActivity.class);
                                                       int[] location=new int[2];
                                                       ih.single_iv.getLocationOnScreen(location);
                                                       intent.putExtra("left", location[0]);
                                                       intent.putExtra("top", location[1]);
                                                       intent.putExtra("height",  ih.single_iv.getHeight());
                                                       intent.putExtra("width", ih.single_iv.getWidth());
                                                       intent.putExtra("position",0);
                                                        List<String> list=new ArrayList<>();
                                                       list.add(new_imgs.get(0));
                                                       intent.putStringArrayListExtra("imgs", (ArrayList<String>) list);
                                                       context.overridePendingTransition(0, 0);
                                                       context.startActivity(intent);
                                                   }

                                                   break;
                                           }

                                           return true;
                                       });


                                   }

                                   @Override
                                   public void onLoadStarted(@Nullable Drawable placeholder) {
                                       super.onLoadStarted(placeholder);
                                       ih.single_iv.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                                       ih.single_iv.setOnTouchListener(new View.OnTouchListener() {
                                           @Override
                                           public boolean onTouch(View view, MotionEvent motionEvent) {
                                               return false;
                                           }
                                       });
                                   }

                                   @Override
                                   public void onLoadFailed(@Nullable Drawable errorDrawable) {
                                       super.onLoadFailed(errorDrawable);
                                       ih.single_iv.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                                       ih.single_iv.setOnTouchListener(new View.OnTouchListener() {
                                           @Override
                                           public boolean onTouch(View view, MotionEvent motionEvent) {
                                               return false;
                                           }
                                       });
                                   }
                               });

                   }else {
                       ih.nineGrid.setImagesData(new_imgs,NineGridImageView.STYLE_GRID);
                       ih.nineGrid.setVisibility(View.VISIBLE);
                   }
                ih.rootView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle=new Bundle();
                        bundle.putInt("id",dataBean.getUserDynamicId());
                        RxActivityTool.skipActivity(context, DynamicDetailActivity.class,bundle);
                    }
                });
                ih.chat_rl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle=new Bundle();
                        bundle.putInt("id",dataBean.getUserDynamicId());
                        RxActivityTool.skipActivity(context, DynamicDetailActivity.class,bundle);
                    }
                });
                break;
            case 1:
                if(dataBean.getDynamicVideoWidth()>=dataBean.getDynamicVideoHeight()){
                    RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
                            LinearLayout.LayoutParams.MATCH_PARENT,ToolsUtils.dip2px(context,170)
                    );
                    ih.video_layout.setLayoutParams(lp);
                    ih.tv_duration.setVisibility(View.VISIBLE);
                    ih.tv_duration.setText(DateUtils.timeParse(dataBean.getDynamicVideoTime()));
                }else{
                    RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
                            ToolsUtils.dip2px(context,170),ToolsUtils.dip2px(context,270)
                    );
                    ih.video_layout.setLayoutParams(lp);
                    ih.tv_duration_right.setVisibility(View.VISIBLE);
                    ih.tv_duration_right.setText(DateUtils.timeParse(dataBean.getDynamicVideoTime()));
                }
                ih.video_layout.setVisibility(View.VISIBLE);
                Glide.with(context)
                         .asBitmap()
                        .load(dataBean.getDynamicImgs())
                        .thumbnail(0.2f)
                      .into(new SimpleTarget<Bitmap>() {
                          @Override
                          public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                               ih.img_video.setImageBitmap(resource);


                          }

                          @Override
                          public void onLoadFailed(@Nullable Drawable errorDrawable) {
                              super.onLoadFailed(errorDrawable);
                              ih.img_video.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                          }

                          @Override
                          public void onLoadStarted(@Nullable Drawable placeholder) {
                              super.onLoadStarted(placeholder);
                              ih.img_video.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                          }
                      });
                ih.rootView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle=new Bundle();
                        bundle.putInt("id",dataBean.getUserDynamicId());
                        RxActivityTool.skipActivity(context, DynamicVideoDetailActivity.class,bundle);
                    }
                });
                ih.play_video.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle=new Bundle();
                        bundle.putInt("id",dataBean.getUserDynamicId());
                        RxActivityTool.skipActivity(context, DynamicVideoDetailActivity.class,bundle);
                    }
                });
                ih.chat_rl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Bundle bundle=new Bundle();
                        bundle.putInt("id",dataBean.getUserDynamicId());
                        RxActivityTool.skipActivity(context, DynamicVideoDetailActivity.class,bundle);
                    }
                });
                break;
        }


            switch (dataBean.getIsLike()){
                case 0:
                    ih.like_iv.setImageResource(R.mipmap.no_like);
                    break;
                case 1:
                    ih.like_iv.setImageResource(R.mipmap.yes_like);
                    break;
            }
            ih.like_tv.setText(String.valueOf(dataBean.getLikeCount()));
            ih.like_bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                   User onlineUser=UserService
                            .getInstance(context)
                            .getOnlineLoginUser();
                    if(onlineUser==null){
                       RxActivityTool.skipActivity(context, UserLoginActivity.class);
                        return;
                    }
                   switch (dataBean.getIsLike()){
                       case 0:
                           ih.like_iv.setImageResource(R.mipmap.yes_like);
                           ih.like_tv.setText(String.valueOf(dataBean.getLikeCount()+1));
                           dataBean.setIsLike(1);
                           dataBean.setLikeCount(dataBean.getLikeCount()+1);
                           set_dynamic_like(onlineUser.getToken(),dataBean.getUserDynamicId());
                           break;
                        default:
                            ih.like_iv.setImageResource(R.mipmap.no_like);
                            ih.like_tv.setText(String.valueOf(dataBean.getLikeCount()-1));
                            dataBean.setIsLike(0);
                            dataBean.setLikeCount(dataBean.getLikeCount()-1);
                            set_dynamic_no_like(onlineUser.getToken(),dataBean.getUserDynamicId());
                            break;
                   }
                }
            });
            ih.guest_tv.setText(String.valueOf(dataBean.getGuestCount()));



   }

   @Override
   public int getItemCount() {
       return dataBeanList.size();
   }
   public void refreshList(List<DynamicDetail> dataBeans) {
       dataBeanList.removeAll(dataBeanList);
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void appendList(List<DynamicDetail> dataBeans) {
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void clearList() {
       dataBeanList.removeAll(this.dataBeanList);
       notifyDataSetChanged();
   }


   public  class IndexHolder extends RecyclerView.ViewHolder{

             public View rootView;
         public CircleImageView cir;
         public TextView user_nickname,content,address,expand,time;
         public ImageView sex;
        public TextView km;
        public NineGridImageView<String> nineGrid;
        public ImageView single_iv;
        public View nav_location;
        public float origin_x=0;
        public  float origin_y=0;
        public View chat_rl;
        public View like_bt;
        public ImageView like_iv;
        public TextView like_tv;
        public TextView guest_tv;
       public RelativeLayout video_layout;
       public IjkVideoView videoView;
       public ImageView img_video;
       public TextView tv_duration;
       public boolean isPlay=false;
       public View play_video;
       public TextView tv_duration_right;
        IndexHolder(@NonNull View itemView) {
           super(itemView);
           rootView=itemView;
            cir=itemView.findViewById(R.id.cir);
            user_nickname=itemView.findViewById(R.id.user_nickname);
            content=itemView.findViewById(R.id.content);
            address=itemView.findViewById(R.id.address);
            sex=itemView.findViewById(R.id.sex);
            expand=itemView.findViewById(R.id.expand);
            time=itemView.findViewById(R.id.time);
            km=itemView.findViewById(R.id.km);
            single_iv=itemView.findViewById(R.id.single_iv);
            nineGrid=itemView.findViewById(R.id.nineGrid);
            nineGrid.setAdapter(mAdapter);
            nineGrid.setItemImageClickListener(new ItemImageClickListener<String>() {
                @Override
                public void onItemImageClick(Context context, ImageView imageView, int index, List<String> list) {

                }
            });
            nineGrid.setItemImageLongClickListener(new ItemImageLongClickListener<String>() {
                @Override
                public boolean onItemImageLongClick(Context context, ImageView imageView, int index, List<String> list) {

                    return true;
                }
            });
            nav_location=itemView.findViewById(R.id.nav_location);
            chat_rl=itemView.findViewById(R.id.chat_rl);
            like_bt=itemView.findViewById(R.id.like_bt);
            like_iv=itemView.findViewById(R.id.like_iv);
            like_tv=itemView.findViewById(R.id.like_tv);
            guest_tv=itemView.findViewById(R.id.guest_tv);
            video_layout=itemView.findViewById(R.id.video_layout);
            videoView=itemView.findViewById(R.id.videoView);
            img_video=itemView.findViewById(R.id.img_video);
            tv_duration=itemView.findViewById(R.id.tv_duration);
            play_video=itemView.findViewById(R.id.play_video);
            tv_duration_right=itemView.findViewById(R.id.tv_duration_right);
        }
   }

    private NineGridImageViewAdapter<String> mAdapter = new NineGridImageViewAdapter<String>() {
        @SuppressLint("CheckResult")
        @Override
        protected void onDisplayImage(Context context, ImageView imageView, String s) {
            Glide.with(context)
                    .load(s)
                    .thumbnail(0.2f)
                     .into(new SimpleTarget<Drawable>() {
                         @Override
                         public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                              imageView.setImageDrawable(resource);
                         }

                         @Override
                         public void onLoadStarted(@Nullable Drawable placeholder) {
                             super.onLoadStarted(placeholder);
                             imageView.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                         }

                         @Override
                         public void onLoadFailed(@Nullable Drawable errorDrawable) {
                             super.onLoadFailed(errorDrawable);
                             imageView.setImageDrawable(new ColorDrawable(ActivityCompat.getColor(context,R.color.light_gray)));
                         }
                     });
        }

        @Override
        protected ImageView generateImageView(Context context) {
            return super.generateImageView(context);
        }

        @Override
        protected void onItemImageClick(Context context1, ImageView imageView, int index, List<String> list) {
            Intent intent=new Intent(context, DropImgsShowActivity.class);
            int[] location=new int[2];
            imageView.getLocationOnScreen(location);
            intent.putExtra("left", location[0]);
            intent.putExtra("top", location[1]);
            intent.putExtra("height", imageView.getHeight());
            intent.putExtra("width",imageView.getWidth());
            intent.putExtra("position",index);
            intent.putStringArrayListExtra("imgs", (ArrayList<String>) list);
            context.overridePendingTransition(0, 0);
            context.startActivity(intent);
        }

        @Override
        protected boolean onItemImageLongClick(Context context, ImageView imageView, int index, List<String> list) {

            return true;
        }
    };



   public void set_dynamic_like(String token,Integer userDynamicId){
       UserDynamicLikeNetImpl
               .set_like_dynamic(token, userDynamicId, token+"_set_like_dynamic_"+userDynamicId, new StringCallback() {
                   @Override
                   public void onSuccess(Response<String> response) {

                   }
               });
   }
    public void set_dynamic_no_like(String token,Integer userDynamicId){
        UserDynamicLikeNetImpl
                .set_no_like_dynamic(token, userDynamicId, token+"_set_no_like_dynamic_"+userDynamicId, new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {

                    }
                });
    }



    public synchronized void openMapDialog(String fromAddress,String toaddress,String fromlon,String fromlat,String tolon,String tolat){
        BottomDialog  mapDialog= BottomDialog.create(context.getSupportFragmentManager())
                .setLayoutRes(R.layout.dialog_select_nav_map)
                .setCancelOutside(false)
                .setDimAmount(0.4f)
                .setTag("mapDialog");
          mapDialog.setViewListener(new BottomDialog.ViewListener() {
            @Override
            public void bindView(View v) {
                v.findViewById(R.id.cancel)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                mapDialog.dismiss();
                            }
                        });
                v.findViewById(R.id.amap_bt)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                mapDialog.dismiss();
                                OpenLocalMapUtil.openGaoDeMap(context,
                                        context.getString(R.string.app_name),
                                        fromlat,
                                        fromlon,
                                        tolat,
                                        tolon);
                            }
                        });
                v.findViewById(R.id.baidu_bt)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                                mapDialog.dismiss();
                                double[]  from= OpenLocalMapUtil.gaoDeToBaidu(Double.parseDouble(fromlon),Double.parseDouble(fromlat));
                                double[]  to= OpenLocalMapUtil.gaoDeToBaidu(Double.parseDouble(tolon),Double.parseDouble(tolat));
                                OpenLocalMapUtil.openBaiDuMap(
                                        fromAddress,toaddress,context,
                                        context.getString(R.string.app_name),
                                        from[0]+"",
                                        from[1]+"",
                                        to[0]+"",
                                        to[1]+"");
                            }
                        });
                v.findViewById(R.id.tencent_bt)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                mapDialog.dismiss();
                             double[]  from= OpenLocalMapUtil.gaoDeToBaidu(Double.parseDouble(fromlon),Double.parseDouble(fromlat));
                                double[]  to= OpenLocalMapUtil.gaoDeToBaidu(Double.parseDouble(tolon),Double.parseDouble(tolat));

                               double[] from_t=OpenLocalMapUtil.map_bd2tx(from[1],from[0]);
                                double[] to_t=OpenLocalMapUtil.map_bd2tx(to[1],to[0]);

                                OpenLocalMapUtil.openTencentMap(context,
                                        context.getString(R.string.app_name),
                                        fromAddress,
                                        toaddress,
                                        from_t[0]+"",
                                        from_t[1]+"",
                                        to_t[0]+"",
                                        to_t[1]+"");
                            }
                        });
            }
        });
        mapDialog.show();
    }


}